package cn.ecnu.mapper.forum;

import cn.ecnu.pojo.User;
import cn.ecnu.pojo.forum.Like;
import cn.ecnu.pojo.forum.Post;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LikeMapper {

    // 点赞
    int insertLike(Like like); // 增加一个赞

    // 取消点赞
    @Delete("delete from pinke.`like` where user_id = #{userId} and type_id = #{typeId} and flag = #{flag}")
    int deleteLikeByUidAndTypeId(@Param("userId") Integer userId, @Param("typeId") Integer typeId, @Param("flag") Integer flag); // 通过likeId删除赞

    // 获取一个post的所有点赞用户列表
    List<User> getLikeUserByPostId(@Param("postId") Integer postId);

    // 获取一个comment的所有点赞用户列表
    List<User> getLikeUserByCommentId(@Param("commentId") Integer commentId);

    // 获取一个用户的点赞帖子集合
    List<Post> getPostByUserLike(@Param("userId") Integer userId);

    // 查看一个用户是否点了点赞了一篇post
    @Select("select * from pinke.`like` where user_id = #{userId} and type_id = #{postId} and flag = 0")
    List<Like> getLikeByDoubleIdForPost(@Param("userId") Integer userId, @Param("postId") Integer postId);

    // 查看一个用户是否点赞了一个comment
    @Select("select * from pinke.`like` where user_id = #{userId} and type_id = #{commentId} and flag = 1")
    List<Like> getLikeByDoubleIdForComment(@Param("userId") Integer userId, @Param("commentId") Integer commentId);
}
